package com.indra.pe.bbva.bp.in.util;

import java.lang.reflect.Method;

import com.stefanini.pe.bbva.bp.in.to.Meta;

public class UtilGeneric {

	public static Object invokeMethodSet(Class clase,String methodName,Object object,int ... parameter) throws Exception{
		Method _method = clase.getDeclaredMethod(methodName,Integer.TYPE);
		_method.setAccessible(true);
		_method.invoke(object,parameter);
		return object;
	}
	
	public static Object invokeMethodGet(Class clase,String methodName,Object object) throws Exception{
		Method _method = clase.getDeclaredMethod(methodName);
		_method.setAccessible(true);
		return _method.invoke(object);
	}
 
	public static String getNameMethodGET(String nameField) throws Exception{
		return "get".concat(nameField.substring(0,1).toUpperCase()).concat(nameField.substring(1,nameField.length()));
	}
	
	public static Object getInvokeMethodSuperClass(Class _class,String nameColumn,Object _object) throws Exception{
		Method _method = null;
		try{
			_method = _class.getDeclaredMethod(nameColumn);
		}catch(Exception e){
			_method = null;
		}	
		if(_method==null){
			_method = getMethodSuperClass(_class,nameColumn);
		}
		_method.setAccessible(true);
		return _method.invoke(_object);
	}
	
	private static Method getMethodSuperClass(Class _class, String nameMethod){
		Method method = null;
		try{
			method = _class.getSuperclass().getDeclaredMethod(nameMethod);
		}catch(Exception e){
			method = null;
		}	
		if(method==null){
			method = getMethodSuperClass(_class.getSuperclass(), nameMethod);
		}
		return method;
	}
}
